<?php
#### CONVERT BYTES #############################################################
// Returns the filesize in a readable format
function convert_bytes($bytes) {
	$sizes = Array('B', 'KB', 'MB', 'GB');
	$extention = $sizes[0];

	for ($i = 1; (($i < count($sizes)) && ($bytes >= 1024)); $i++) {
		$bytes = $bytes / 1024;
		$extention = $sizes[$i];
	}

	return round($bytes, 2).' '.$extention;
}

#### CREATE DIR ################################################################
function create_dir_call($path) {
	// If the directory we are trying to upload to does not exist, try and create it
	if (!file_exists($path)) {
		$dirs = explode('/', $path);
		$dirs_copy = $dirs;
		foreach ($dirs as $dir) {
			$paths[] = implode('/', $dirs);
			array_pop($dirs);
		}
		$paths = array_reverse($paths);
		foreach ($paths as $path) {
			if (!file_exists($path)) @mkdir($path, 0777);
		}
	}
	if (!file_exists($path)) die ('Could not make path: '.$path);
}

#### MOVE DIR ##################################################################
function move_dir_call($from, $to) {
	return @rename($from, $to);
}

#### MOVE FILE #################################################################
function move_file_call($from, $to) {
	return @rename($from, $to);
}


#### MOVE DIR CONTENTS #########################################################
function move_dir_contents_call($from, $to) {

	if ($dir = opendir($from)) {
		while ($file = readdir($dir)) {
			if ($file != '.' && $file != '..')
				@rename($from.'/'.$file, $to.'/'.$file);
		}
		closedir($dir);
	}
}

#### DELETE DIR ################################################################
function delete_dir_call($path) {

	// Delete all files contained withing directory
	if ($dir = opendir($path)) {
		while ($file = readdir($dir)) {
			if ($file != '.' && $file != '..') {
				if (is_dir($path.'/'.$file))
					delete_dir_call($path.'/'.$file);
				else
					@unlink($path.'/'.$file);
			}
		}
		closedir($dir);
	}

	// Delete the directory itself
	@unlink($path);
	return @rmdir($path);

}

#### DELETE DIR ################################################################
function delete_file_call($path) {
	return @unlink($path);
}
?>